<?php 
$user=$session->read('User');
$companyid=$session->read("companyid");
?>
<div class="right_side_operate_area">
	<div class="right_side_title left">
    	<h2>
		<?php 
		$companyname=$session->read("companyname");		
		$companyyear=$session->read("economicyear");
		echo $html->link($companyname,"/companys/showinfosummary/".$companyid);
		?>
    	</h2>
    	<div class='clear'></div>
    </div>
    <div class="right item_add_btn">
		<?php 			
			$cuser=$session->read('User');
			if($form->value('CompFinanc.id')){
			$str_title=__("Edit",true);
			}else{
			$str_title=__("Add",true);
			}
    		echo $html->link(__("Cancel",true).$str_title,"/companys/financ/",array("onclick"=>"history.go(-1);return false;"));
    	?>
	</div>
    <div class="clear"></div>
</div>
<div class="right_side_scollbar">
	<div class="detail_info_panel">
		<?php 
		echo $form -> create('CompFinanc', array('url'=>'/companys/editfinanc','enctype'=>'multipart/form-data','onsubmit'=>"return checkdinfo()") ); 
		?>
		<div class="items_list">
			<div class="details_item_line">
				<div class="details_item">
					<div class="form_left_title left"><font style="color:red">*</font>融资时间：</div>
					<div class="form_right_e_input form_date_picker left">
						<?php echo $form->text('CompFinanc.fin_time',
												array("maxlength"=>"10","onfocus"=>"WdatePicker()","style"=>"width:130px"));?>
					</div>
					<div id='timemessage' style='display:none;' class="error_message">请选择融资时间</div>
				</div>			
			</div>
			<div class="details_item_line">
				<div class="details_item">
					<div class="form_left_title left"><font style="color:red">*</font>融资金额：</div>
					<div class="form_right_e_input left">
						<?php echo $form->text('CompFinanc.money',array("placeholder"=>"0.00","onkeydown"=>"checkpricekeyup(this,event)"));?>	
						&nbsp;￥						
					</div>		
					<div id='finmoneymessage' style='display:none;' class="error_message">请填写融资金额</div>
				</div>
			</div>
			<div class="details_item_line">
				<div class="details_item">
					<div class="form_left_title left"><font style="color:red">*</font>金额占股：</div>
					<div class="form_right_e_input left">
						<?php echo $form->text('CompFinanc.percent',array("placeholder"=>"0.00","onkeydown"=>"checkpricekeyup(this,event)"));?>
						&nbsp;%
					</div>	
					<div id='percentmessage' style='display:none;' class="error_message">请填写融资金额占股</div>
				</div>
			</div>
<?php 
foreach($allfinancs as $key=>$financ){
	if (!empty($key)){
		$pid[$key] = $financ;	
	}
}
?>
			<div class="details_item_line">
				<div class="details_item">
	    			<div class="form_left_title left"><?php echo "融资来源" ;?>：</div>
	    			<div class="form_right_e_input left"><?php echo $form->select('CompFinanc.type_id',$pid, null, null,null);?></div>
	   			 <div id='typeemessage' style='display:none;' class="error_message">请选择类型</div>
				</div>
			</div>
			<div class="details_item_line">
				<div class="details_item">
					<div class="form_left_title left"><font style="color:red">*</font>融资渠道：</div>
					<div class="form_right_e_input left">
						<?php echo $form->textarea('CompFinanc.fin_channels');?>
					</div>	
					<div id='finchannelmessage' style='display:none;' class="error_message">请填写融资渠道</div>
				</div>
			</div>
			<div class="details_item_line">
				<div class="details_item">
				   <div class="form_left_title left"><?php echo "财务报表";?>：</div>
				    <div class="form_right_input left">
				 		<?php if($attachments){?>
	                	<div class="file_category_list">
			        		<div id="filelist0" class="file_lists">
			        			<ul class="file_attach">
				                	<?php
				                	$dan="'";
				                	foreach($attachments as $attachment) {
											echo "<li>";
											echo "<span>".$html->link($attachment["file_name"],'/projects/download/'.$attachment["id"],null)."</span>";
											echo "<span class='source_upload_date'>".date("Y-m-d",strtotime($attachment["created"]))."</span>";									
											echo '<span class="source_upload_delete"><a title="删除" onclick="delfile(this,'.$dan.$attachment["id"].$dan.',0)" href="javascript:void(0)"></a></span>';									
											echo "</li>";
									}
				                	?>
				                </ul>
			                </div>
			            </div>
			            <?php }?>
					    <div id="add1" class="left text_box"> 
							<div class="file_add_box">
								<input type="file" id="upload[]" name="upload[]" />
							</div>
						</div>
						<div class="clear"></div>
						<div id="add2" class="left filelist"></div>
						<div class="left clear">
							<div class="left add_sub_file_btn">
								<span onclick="add()" href="#"><?php echo $html->image('list-add.png')?></span>&nbsp;
								<span onclick="remove()" href="#"><?php echo $html->image('list-remove.png')?></span>
						</div>
					</div>
				 </div>
				</div>
			</div>
			<?php
			echo $form->hidden('CompFinanc.owner',array('value' => $cuser['id'])) ;		
			echo $form->hidden('CompFinanc.cid',array('value' => $_SESSION['companyid'])) ;
			?>
		 	<?php
		    echo $form->hidden('CompFinanc.id') ;
			?>
			<div class="details_item_line edit_form_btn">
	            <div class="details_item">
	            	<div class="form_left_title left"></div>
	                <div class="form_add_submit left">
						<?php echo $form->submit(__('Save',true), array("id"=>"adduser","name"=>"submit","class"=>"buttom","div"=>false)) ?>
						 <?php  echo $form->hidden('CompFinanc.id'); ?>
					</div>
	            </div>
       		 </div>
		</div>
	</div>
</div>
<?php echo $this->element('delfileconfirm',array("title"=>"删除提示","message"=>"你确定要删除吗？")) ?>
<?php echo $javascript->link('project.js');?>
<script>
if(!$("#CompFinancId").val()){
$(document).ready(function() {	
  $("#uniform-CompFinancCostType0").children().addClass("checked");
  });
}
function checkdinfo(){
		if($("#CompFinancFinTime").val().trim() == ''){
			$("#timemessage").css('display','block');
			return false;
	  }else{
		 	 $("#timemessage").css('display','none');
		  }
	  if($("#CompFinancMoney").val().trim() == ''){
			$("#finmoneymessage").css('display','block');
			return false;
	  }else{
		 	 $("#finmoneymessage").css('display','none');
		  }
		  
	  if($("#CompFinancFinChannels").val().trim() == ''){
			$("#finchannelmessage").css('display','block');
			return false;
	  }else{
		 	 $("#finchannelmessage").css('display','none');
		  }

	  if($("#CompFinancPercent").val().trim() == ''){
			$("#percentmessage").css('display','block');
			return false;
	  }else{
		 	 $("#percentmessage").css('display','none');
		  }
}
</script>	